package com.tmrnavi.ndktest;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {
    static{ System.loadLibrary("ndktest");}

    private EditText et_a, et_b, et_r;
    private Button bt_cal;
    private EditText et_x0, et_x1, et_x2, et_x3, et_sum;
    private Button bt_sum;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        et_a = findViewById(R.id.edit_a);
        et_b = findViewById(R.id.edit_b);
        et_r = findViewById(R.id.edit_res);
        bt_cal = findViewById(R.id.bt_cal);
        et_x0 = findViewById(R.id.edit_x0);
        et_x1 = findViewById(R.id.edit_x1);
        et_x2 = findViewById(R.id.edit_x2);
        et_x3 = findViewById(R.id.edit_x3);
        et_sum = findViewById(R.id.edit_sumres);
        bt_sum = findViewById(R.id.bt_sum);

        bt_cal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                et_r.setText(String.valueOf(add(Integer.parseInt(et_a.getText().toString()), Integer.parseInt(et_b.getText().toString()))));
            }
        });

        bt_sum.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int[] x = new int[4];
                x[0] = Integer.parseInt(et_x0.getText().toString());
                x[1] = Integer.parseInt(et_x1.getText().toString());
                x[2] = Integer.parseInt(et_x2.getText().toString());
                x[3] = Integer.parseInt(et_x3.getText().toString());
                et_sum.setText(String.valueOf(sum(x)));
            }
        });

    }

    public native int add (int a, int b);
    public native int sum (int[] x);
}